package com.zxy.ziems.server.energy.service;

import com.zxy.btp.common.response.PageResult;
import com.zxy.ziems.server.domain.DeviceMeasureData;
import com.zxy.ziems.server.domain.DeviceMeasureDataIncrementHour;
import com.zxy.ziems.server.dto.DeviceMeasureDateGroupDto;
import com.zxy.ziems.server.energy.pojo.dto.ClassifyDeviceEleDTO;
import com.zxy.ziems.server.energy.pojo.dto.DeviceMeasureDateDTO;
import com.zxy.ziems.server.energy.pojo.entity.DeviceMeasureDataDayEntity;
import com.zxy.ziems.server.energy.pojo.param.DeviceMeasureDataPageParam;
import com.zxy.ziems.server.energy.pojo.param.DeviceMeasureDataQParam;
import com.zxy.ziems.server.energy.pojo.vo.DeviceMeasureDataVO;

import java.math.BigDecimal;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.util.Date;
import java.util.List;
import java.util.Set;

public interface DeviceMeasureDataService {

    /**
     * 获取时间段内设备属性值的平均值（实时值）
     *
     * @param dateType
     * @param start
     * @param end
     * @return
     */
    List<DeviceMeasureDateDTO> getAvg(String dateType, LocalDate start, LocalDate end,
                                      Set<String> deviceIds, String devicePropertyId);

    /**
     * 获取时间段内设备属性值的和值（增量值）
     *
     * @param dateType
     * @param start
     * @param end
     * @return
     */
    List<DeviceMeasureDateDTO> getSum(String dateType, LocalDate start, LocalDate end,
                                      Set<String> deviceIds, String devicePropertyId);

    /**
     * 获取时间段内设备属性的和值（按设备统计，增量值）
     *
     * @param dateType
     * @param start
     * @param end
     * @param deviceIds
     * @param devicePropertyId
     * @return
     */
    List<DeviceMeasureDateGroupDto> getDeviceSum(String dateType, LocalDate start, LocalDate end, Set<String> deviceIds, String devicePropertyId, List<String> classifyIds);

    /**
     * 获取时间段内设备属性的和值（按设备统计，增量值）
     *
     * @param dateType
     * @param start
     * @param end
     * @param deviceIds
     * @param devicePropertyId
     * @return
     */
    List<DeviceMeasureDateGroupDto> getDeviceRealSum(String dateType, LocalDate start, LocalDate end, Set<String> deviceIds, String devicePropertyId, List<String> classifyIds);


    /**
     * 获取时间段内设备属性的和值（按设备统计，实时值）
     *
     * @param dateType
     * @param start
     * @param end
     * @param deviceIds
     * @param devicePropertyId
     * @return
     */
    List<DeviceMeasureDateGroupDto> getDeviceAvg(String dateType, LocalDate start, LocalDate end, Set<String> deviceIds, String devicePropertyId, List<String> classifyIds);

    /**
     * 根据设备id查询测量数据
     *
     * @param param
     * @return
     */
    PageResult<DeviceMeasureDataVO> pageByDevice(DeviceMeasureDataPageParam param);

    /**
     * 查询一段时间内检测数据
     *
     * @param startTime
     * @param endTime
     * @return
     */
    List<DeviceMeasureData> list(Date startTime, Date endTime, List<String> ids);

    /**
     * 汇总增量值
     *
     * @param deviceType
     * @param dataType
     * @param startDate
     * @param endDate
     * @return
     */
    BigDecimal sumIncrementValByTypeAndDataType(String deviceType, String dataType, LocalDateTime startDate, LocalDateTime endDate);

    List<DeviceMeasureDateGroupDto> listDeviceHour(String startDay, String endDay, String classifyId, Set<String> deviceIdSet, String dataTypeId);

    /**
     * 获取设备当前值
     *
     * @param deviceIds
     * @return
     */
    List<DeviceMeasureData> getCurrentValByDeviceIds(List<String> deviceIds);

    /**
     * 获取天统计数据
     *
     * @param date
     * @return
     */
    List<DeviceMeasureDataDayEntity> getDayDataByDate(LocalDate date);

    /**
     * 获取天小时数据
     *
     * @param dateTime
     * @return
     */
    List<DeviceMeasureDataIncrementHour> getDayHourDataByDate(LocalDateTime dateTime);

    /**
     * 获取天统计数据量
     *
     * @param date
     * @return
     */
    Long countDayDataByDate(LocalDate date);

    /**
     * 获取当前小时统计量
     *
     * @param date
     * @return
     */
    Long countDayHourDataByDate(LocalDateTime date);

    /**
     * 批量保存
     *
     * @param insertDataList
     */
    void batchSave(List<DeviceMeasureDataDayEntity> insertDataList);

    PageResult<DeviceMeasureDataVO> measureDataPageList(DeviceMeasureDataQParam param);

    /**
     * list
     *
     * @return
     */
    List<DeviceMeasureData> list();

    List<ClassifyDeviceEleDTO> getDeviceTypeEle(String dateType, LocalDate start, LocalDate end, Set<String> deviceIds, String dataTypeId, List<String> classifyIds);
}
